home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / Assert.c next >
C/C++ Source or Header  |  1998-09-09  |  3KB  |  205 lines

  1. /*
  2. **    $Id: Assert.c 42.1 1997/07/06 09:01:09 olsen Exp olsen $
  3. **
  4. **    :ts=8
  5. */
  6.  
  7. /****************************************************************************/
  8.  
  9. #include <dos/dos.h>
  10.  
  11. #include <clib/exec_protos.h>
  12. #include <clib/dos_protos.h>
  13.  
  14. #include <pragmas/exec_pragmas.h>
  15. #include <pragmas/dos_pragmas.h>
  16.  
  17. extern void kprintf(const char *,...);
  18.  
  19. /****************************************************************************/
  20.  
  21. static int _indent_level;
  22.  
  23. /****************************************************************************/
  24.  
  25. void
  26. _INDENT(void)
  27. {
  28.     int i;
  29.  
  30.     for(i = 0 ; i < _indent_level ; i++)
  31.         kprintf("   ");
  32. }
  33.  
  34. void
  35. _SHOWVALUE(
  36.     unsigned long value,
  37.     int size,
  38.     const char *name,
  39.     const char *file,
  40.     int line)
  41. {
  42.     char *fmt;
  43.  
  44.     switch(size)
  45.     {
  46.         case 1:
  47.  
  48.             fmt = "%s:%ld:%s = %ld, 0x%02lx";
  49.             break;
  50.  
  51.         case 2:
  52.  
  53.             fmt = "%s:%ld:%s = %ld, 0x%04lx";
  54.             break;
  55.  
  56.         default:
  57.  
  58.             fmt = "%s:%ld:%s = %ld, 0x%08lx";
  59.             break;
  60.     }
  61.  
  62.     _INDENT();
  63.  
  64.     kprintf(fmt,file,line,name,value,value);
  65.  
  66.     if(size == 1 && value < 256)
  67.     {
  68.         if(value < ' ' || (value >= 127 && value < 160))
  69.             kprintf(", '\\x%02lx'",value);
  70.         else
  71.             kprintf(", '%lc'",value);
  72.     }
  73.  
  74.     kprintf("\n");
  75. }
  76.  
  77. /****************************************************************************/
  78.  
  79. void
  80. _SHOWSTRING(
  81.     const char *string,
  82.     const char *name,
  83.     const char *file,
  84.     int line)
  85. {
  86.     _INDENT();
  87.     kprintf("%s:%ld:%s = 0x%08lx \"%s\"\n",file,line,name,string,string);
  88. }
  89.  
  90. /****************************************************************************/
  91.  
  92. void
  93. _SHOWMSG(
  94.     const char *string,
  95.     const char *file,
  96.     int line)
  97. {
  98.     _INDENT();
  99.     kprintf("%s:%ld:%s\n",file,line,string);
  100. }
  101.  
  102. /****************************************************************************/
  103.  
  104. void
  105. _ENTER(
  106.     const char *file,
  107.     int line,
  108.     const char *function)
  109. {
  110.     _INDENT();
  111.     kprintf("%s:%ld:Entering %s\n",file,line,function);
  112.     _indent_level++;
  113. }
  114.  
  115. void
  116. _LEAVE(
  117.     const char *file,
  118.     int line,
  119.     const char *function)
  120. {
  121.     _indent_level--;
  122.     _INDENT();
  123.     kprintf("%s:%ld: Leaving %s\n",file,line,function);
  124. }
  125.  
  126. void
  127. _RETURN(
  128.     const char *file,
  129.     int line,
  130.     const char *function,
  131.     unsigned long result)
  132. {
  133.     _indent_level--;
  134.     _INDENT();
  135.     kprintf("%s:%ld: Leaving %s (result 0x%08lx, %ld)\n",file,line,function,result,result);
  136. }
  137.  
  138. /****************************************************************************/
  139.  
  140. void
  141. _ASSERT(
  142.     int x,
  143.     const char *xs,
  144.     const char *file,
  145.     int line,
  146.     const char *function)
  147. {
  148. #ifdef CONFIRM
  149.     STATIC BOOL ScrollMode    = FALSE;
  150.     STATIC BOOL BatchMode    = FALSE;
  151.  
  152.     if(BatchMode == FALSE)
  153.     {
  154.         if(x == 0)
  155.         {
  156.             kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
  157.                     file,
  158.                     line,
  159.                     xs,
  160.                     function);
  161.  
  162.             if(ScrollMode == FALSE)
  163.             {
  164.                 ULONG Signals;
  165.  
  166.                 SetSignal(0,SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
  167.  
  168.                 kprintf(" ^C to continue, ^D to enter scroll mode, ^E to enter batch mode\r");
  169.  
  170.                 Signals = Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D | SIGBREAKF_CTRL_E);
  171.  
  172.                 if(Signals & SIGBREAKF_CTRL_D)
  173.                 {
  174.                     ScrollMode = TRUE;
  175.  
  176.                     kprintf("Ok, entering scroll mode\033[K\n");
  177.                 }
  178.                 else if (Signals & SIGBREAKF_CTRL_E)
  179.                 {
  180.                     BatchMode = TRUE;
  181.  
  182.                     kprintf("Ok, entering batch mode\033[K\n");
  183.                 }
  184.                 else
  185.                 {
  186.                     /* Continue */
  187.  
  188.                     kprintf("\033[K\r");
  189.                 }
  190.             }
  191.         }
  192.     }
  193. #else
  194.     if(x == 0)
  195.     {
  196.         _INDENT();
  197.         kprintf("%s:%ld:Expression `%s' failed assertion in %s().\n",
  198.                 file,
  199.                 line,
  200.                 xs,
  201.                 function);
  202.     }
  203. #endif    /* CONFIRM */
  204. }
  205.